/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * analizainput
 * 
 * analizainput is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * analizainput is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "busqueda-input.h"
#include <iostream>
using namespace std;

void busquedaInput::descomponerBigramas(string palabra){
	string bigramaAux;

	poseeBigrama = true;
	bigramaAux = "$" + palabra.substr(0,1);
//	cout << bigramaAux << endl;
	bigrama.push_back(bigramaAux);

	for(int i=0;i<palabra.length()-1;i++){
		bigramaAux = palabra.substr(i,2);
//		cout << bigramaAux << endl;
		bigrama.push_back(bigramaAux);
	}

	bigramaAux = palabra.substr(palabra.length()-1,1) + "$";
//	cout << bigramaAux << endl;
	bigrama.push_back(bigramaAux);

}

void busquedaInput::validarInput(string palabra){
	size_t existeAsterisco;
	size_t existePregunta;
	
	cout << "validando " << palabra << endl;

	existeAsterisco = palabra.find('*');
	existePregunta = palabra.find('?');
	
	if(existeAsterisco != string::npos || existePregunta != string::npos){
//		cout << "la palabra debe ser descompuesta en bigramas" << endl;
		descomponerBigramas(palabra);
	}else{
		poseeTermino = true;
		termino.push_back(palabra);
	}
};

void busquedaInput::removerDuplicados(){
	bigrama.sort();
	bigrama.unique();
	termino.sort();
	termino.unique();
};

void busquedaInput::mostrarListas(){
	list<string>::iterator it;
	
	if(poseeBigrama == true){
		bigrama.front();
		for(it=bigrama.begin() ; it != bigrama.end(); it++)
			cout << *it << endl;
	}

	if(poseeTermino == true){
		termino.front();
		for(it=termino.begin() ; it != termino.end(); it++)
			cout << *it << endl;
	}
		
}

